const koa = require('koa')

const { serverStaticPlugin } = require('./plugins/serverPluginStaticPlugin.js')
const { moduleRewritePlugin } = require('./plugins/serverPluginModuleRewrite.js')
const { moduleResolvePlugin } = require('./plugins/serverPluginModuleResolvePlugin')
const { htmlRewritePlugin } = require('./plugins/serverPluginhtmlRewrite.js')
const { vuePlugin } = require('./plugins/serverPluginVue')
/**
 *  这个函数用于创建服务器实例
 * @returns 返回服务器实例
 */
const createServer = () => {
    const app = new koa()

    const root = process.cwd() //返回运行的根目录
    //创建上下文
    const context = {
        root,
        app
    }
    // 插件的集合
    const resolvePlugin = [

        htmlRewritePlugin,
        moduleResolvePlugin,
        //拼接module的模块
        moduleRewritePlugin,
        vuePlugin,
        //实现静态服务的功能
        serverStaticPlugin
    ];
    resolvePlugin.forEach(plugin => plugin(context))
    return app;
}

module.exports = createServer;